using UnityEngine;

public class MonoSingleton<T> : MonoBehaviour where T : MonoSingleton<T>
{
	private static T _instance;

	[SerializeField]
	private Color _tagColor = Color.white;

	private string _tag;

	public static T Instance
	{
		get
		{
			if ((Object)_instance == (Object)null)
			{
				_instance = (T)UnityEngine.Object.FindObjectOfType(typeof(T));
			}
			return _instance;
		}
	}

	public string Tag
	{
		get
		{
			if (string.IsNullOrEmpty(_tag))
			{
				_tag = "[" + typeof(T).ToString() + "] ";
			}
			return _tag;
		}
	}

	protected virtual void Awake()
	{
		_instance = (this as T);
		if (base.gameObject.transform.parent == null)
		{
			Object.DontDestroyOnLoad(base.gameObject);
		}
	}

	protected virtual void OnDestroy()
	{
		if (_instance == this)
		{
			_instance = (T)null;
		}
	}
}
